const ALLOW_AMPLIFIED_VOLUME_KEY = 'allow-volume-above-100-percent';
-const VolumeType = {
- OUTPUT: 0,
- INPUT: 1,
-};
-
// Each Gvc.MixerControl is a connection to PulseAudio,
// so it's better to make it a singleton
let _mixerControl;
}
};
-var VolumeMenu = class extends PopupMenu.PopupMenuSection {
- constructor(control) {
- super();
+var Indicator = GObject.registerClass(
+class Indicator extends PanelMenu.SystemIndicator {
+ _init() {
+ super._init();
- this.hasHeadphones = false;
+ this._primaryIndicator = this._addIndicator();
+ this._inputIndicator = this._addIndicator();
- this._control = control;
+ this._primaryIndicator.reactive = true;
+ this._inputIndicator.reactive = true;
+
+ this._primaryIndicator.connect('scroll-event',
+ (actor, event) => this._handleScrollEvent(this._output, event));
+ this._inputIndicator.connect('scroll-event',
+ (actor, event) => this._handleScrollEvent(this._input, event));
+
+ const volumeMenu = new PopupMenu.PopupMenuSection();
+
+ this._control = getMixerControl();
this._control.connectObject(
'state-changed', () => this._onControlStateChanged(),
'default-sink-changed', () => this._readOutput(),
this);
this._output = new OutputStreamSlider(this._control);
- this._output.connect('stream-updated',
- () => this.emit('output-icon-changed'));
- this.addMenuItem(this._output.item);
+ this._output.connect('stream-updated', () => {
+ const icon = this._output.getIcon();
+
+ if (icon)
+ this._primaryIndicator.icon_name = icon;
+ this._primaryIndicator.visible = icon !== null;
+ });
+ volumeMenu.addMenuItem(this._output.item);
this._input = new InputStreamSlider(this._control);
- this._input.item.connect('notify::visible',
- () => this.emit('input-visible-changed'));
- this._input.connect('stream-updated',
- () => this.emit('input-icon-changed'));
- this.addMenuItem(this._input.item);
+ this._input.connect('stream-updated', () => {
+ const icon = this._input.getIcon();
+
+ if (icon)
+ this._inputIndicator.icon_name = icon;
+ });
+ volumeMenu.addMenuItem(this._input.item);
- this.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
+ this._input.item.actor.bind_property('visible',
+ this._inputIndicator, 'visible',
+ GObject.BindingFlags.SYNC_CREATE);
- this._onControlStateChanged();
- }
+ this.menu.addMenuItem(volumeMenu);
- scroll(type, event) {
- return type === VolumeType.INPUT
- ? this._input.scroll(event)
- : this._output.scroll(event);
+ this._onControlStateChanged();
}
_onControlStateChanged() {
- if (this._control.get_state() == Gvc.MixerControlState.READY) {
+ if (this._control.get_state() === Gvc.MixerControlState.READY) {
this._readInput();
this._readOutput();
} else {
- this.emit('output-icon-changed');
+ this._primaryIndicator.hide();
}
}
this._input.stream = this._control.get_default_source();
}
- getIcon(type) {
- return type === VolumeType.INPUT
- ? this._input.getIcon()
- : this._output.getIcon();
- }
-
- getLevel(type) {
- return type === VolumeType.INPUT
- ? this._input.getLevel()
- : this._output.getLevel();
- }
-
- getMaxLevel(type) {
- return type === VolumeType.INPUT
- ? this._input.getMaxLevel()
- : this._output.getMaxLevel();
- }
-
- getInputVisible() {
- return this._input.item.visible;
- }
-};
-
-var Indicator = GObject.registerClass(
-class Indicator extends PanelMenu.SystemIndicator {
- _init() {
- super._init();
-
- this._primaryIndicator = this._addIndicator();
- this._inputIndicator = this._addIndicator();
-
- this._primaryIndicator.reactive = true;
- this._inputIndicator.reactive = true;
-
- this._primaryIndicator.connect('scroll-event',
- (actor, event) => this._handleScrollEvent(VolumeType.OUTPUT, event));
- this._inputIndicator.connect('scroll-event',
- (actor, event) => this._handleScrollEvent(VolumeType.INPUT, event));
-
- this._control = getMixerControl();
- this._volumeMenu = new VolumeMenu(this._control);
- this._volumeMenu.connect('output-icon-changed', () => {
- let icon = this._volumeMenu.getIcon(VolumeType.OUTPUT);
-
- if (icon != null)
- this._primaryIndicator.icon_name = icon;
- this._primaryIndicator.visible = icon !== null;
- });
-
- this._inputIndicator.visible = this._volumeMenu.getInputVisible();
- this._volumeMenu.connect('input-visible-changed', () => {
- this._inputIndicator.visible = this._volumeMenu.getInputVisible();
- });
- this._volumeMenu.connect('input-icon-changed', () => {
- let icon = this._volumeMenu.getIcon(VolumeType.INPUT);
-
- if (icon !== null)
- this._inputIndicator.icon_name = icon;
- });
-
- this.menu.addMenuItem(this._volumeMenu);
- }
-
- _handleScrollEvent(type, event) {
- const result = this._volumeMenu.scroll(type, event);
- if (result == Clutter.EVENT_PROPAGATE || this.menu.actor.mapped)
+ _handleScrollEvent(item, event) {
+ const result = item.scroll(event);
+ if (result === Clutter.EVENT_PROPAGATE || this.menu.actor.mapped)
return result;
- const gicon = new Gio.ThemedIcon({ name: this._volumeMenu.getIcon(type) });
- const level = this._volumeMenu.getLevel(type);
- const maxLevel = this._volumeMenu.getMaxLevel(type);
+ const gicon = new Gio.ThemedIcon({name: item.getIcon()});
+ const level = item.getLevel();
+ const maxLevel = item.getMaxLevel();
Main.osdWindowManager.show(-1, gicon, null, level, maxLevel);
return result;
}